package com.compass.doctor.ui.chat.viewholder;

import static com.compass.framework.utils.ResUtilsKt.getDrawableResource;

import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.compass.doctor.R;
import com.compass.doctor.databinding.ChatMessagePreViewHolderBinding;
import com.compass.doctor.databinding.ChatMessagePrescriptionViewHolderBinding;
import com.compass.doctor.ui.chat.ImDrugAdapter;
import com.compass.doctor.ui.chat.attachment.PreConsultationAttachment;
import com.compass.doctor.ui.chat.attachment.PrescriptionAttachment;
import com.compass.framework.model.ImDrug;
import com.compass.framework.utils.LogUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.netease.yunxin.kit.chatkit.ui.common.MessageHelper;
import com.netease.yunxin.kit.chatkit.ui.databinding.ChatBaseMessageViewHolderBinding;
import com.netease.yunxin.kit.chatkit.ui.fun.view.message.viewholder.FunChatBaseMessageViewHolder;
import com.netease.yunxin.kit.chatkit.ui.model.ChatMessageBean;

import java.lang.reflect.Type;
import java.util.ArrayList;

/**
 * Description：
 * Date:2024/3/2 9:24
 */
public class PreConsultationViewHolder extends FunChatBaseMessageViewHolder {
    public static final String TAG = "InquiryViewHolder";
    ChatMessagePreViewHolderBinding binding;
    PreConsultationAttachment attachment;
    ImDrugAdapter drugAdapter;
    ArrayList<ImDrug> imDrugs = new ArrayList<>();

    public PreConsultationViewHolder(@NonNull ChatBaseMessageViewHolderBinding parent, int viewType) {
        super(parent, viewType);
    }

    @Override
    protected void addViewToMessageContainer() {
        binding = ChatMessagePreViewHolderBinding.inflate(LayoutInflater.from(parent.getContext()), getMessageContainer(), true);

    }


    @Override
    public void bindData(ChatMessageBean message, ChatMessageBean lastMessage) {
        super.bindData(message, lastMessage);
        currentMessage = message;
        attachment = (PreConsultationAttachment) message.getMessageData().getMessage().getAttachment();
        if (attachment == null) {
            return;
        }

        //设置ViewHolder展示UI的内容
        binding.patientName.setText(attachment.getPatientName());
        binding.mainSuit.setText("主诉："+attachment.getMainSuit());
        binding.historyIllness.setText("现病史："+attachment.getHistoryIllness());
        binding.previousHistory.setText("既往史："+attachment.getPreviousHistory());
        binding.individualHis.setText("个人史："+attachment.getIndividualHis());
        binding.allergicHistory.setText("过敏史："+attachment.getAllergicHistory());

        Glide.with(parent.getContext()).load(attachment.getPatientAvatar())
                .skipMemoryCache(false) //启用内存缓存
                .diskCacheStrategy(DiskCacheStrategy.RESOURCE) //磁盘缓存策略
                .apply(RequestOptions.circleCropTransform()) // 圆形
                .into(binding.ivHead);

        binding.tvAge.setText(attachment.getPatientAge());
        binding.ivSex.setBackground(attachment.getSex().equals("1") ? getDrawableResource(R.mipmap.icon_male) : getDrawableResource(R.mipmap.icon_female));

    }


    @Override
    protected void onMessageBackgroundConfig(ChatMessageBean messageBean) {
        super.onMessageBackgroundConfig(messageBean);
        boolean isReceivedMsg = MessageHelper.isReceivedMessage(messageBean);
        View firstChild = baseViewBinding.messageContainer.getChildAt(0);
        if (isReceivedMsg) {
            firstChild.setBackgroundResource(R.drawable.bg_custom_message);
        } else {
            firstChild.setBackgroundResource(R.drawable.bg_custom_message_out);
        }
    }
}
